package com.example.myapplication.activity;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.transition.Transition;
import com.example.myapplication.Fragment.SongDetailFragment;
import com.example.myapplication.Fragment.LrcFragment;
import com.example.myapplication.R;
import com.example.myapplication.adapter.viewPagerAdapter.SongDetailAdapter;
import com.example.myapplication.entity.HotSongs;
import com.example.myapplication.tools.BarTransparent;
import com.google.android.material.tabs.TabLayout;

import java.util.ArrayList;
import java.util.List;

import jp.wasabeef.glide.transformations.BlurTransformation;

public class SongDetail1Activity extends AppCompatActivity {
    private TabLayout tab_layout_song_detail;
    private ViewPager view_page_song_detail;
    private View container;
    private HotSongs hotSongs;
    private TextView back_song;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_viewpage_test);
        BarTransparent.makeStatusBarTransparent(this);
        view_page_song_detail = findViewById(R.id.view_page_song_detail);
        tab_layout_song_detail = findViewById(R.id.tab_layout_song_detail);
        container = findViewById(R.id.container);
        back_song = findViewById(R.id.back_song);
        back_song.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        Intent intent =getIntent();
        Bundle bundle = intent.getExtras();
        hotSongs = (HotSongs) bundle.getSerializable("song");
        String url = hotSongs.getAl().getPicUrl();
        //设置虚化的背景图片
        RequestOptions options= RequestOptions
                .bitmapTransform(new BlurTransformation(100, 5));
        SimpleTarget<Drawable> simpleTarget = new SimpleTarget<Drawable>() {
            @Override
            public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
                container.setBackground(resource);
            }
        };
        Glide.with(this)
                .load(url)
                .apply(options)
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(simpleTarget);
        List<Fragment> fragmentList = new ArrayList<>();
        if(LrcFragment.fragment!=null){
            LrcFragment.fragment = null;
        }
        if(SongDetailFragment.fragment!=null){
            SongDetailFragment.fragment = null;
        }
        fragmentList.add(new SongDetailFragment().newInstance(bundle));
        fragmentList.add(new LrcFragment().newInstance(bundle));
        SongDetailAdapter adapter = new SongDetailAdapter(getSupportFragmentManager(),fragmentList);
        view_page_song_detail.setAdapter(adapter);
        tab_layout_song_detail.setupWithViewPager(view_page_song_detail);
    }
}